package mashuaiproject.mashuaiproject.mapper;

import mashuaiproject.mashuaiproject.dto.AddFriendsUser;
import mashuaiproject.mashuaiproject.dto.OnlieUserMesDto;
import mashuaiproject.mashuaiproject.model.AddFriend;
import mashuaiproject.mashuaiproject.model.OnlineCommuntiy;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface OnlieCoummtiyMapper {
    @Insert("insert into onlinecommuntiy(userId,gmt_create,site,content,withUserId)values(" +
            "#{userId},#{gmt_create},#{site},#{content},#{withUserId})")
    void insetQunLiao(OnlineCommuntiy onlineCommuntiy);

    @Select("select *from onlinecommuntiy where  withUserId=0 order by gmt_create asc")
    List<OnlineCommuntiy> selectAllCommuntiy();
    @Select("select *from onlinecommuntiy where  withUserId=0 order by gmt_create desc")
    List<OnlineCommuntiy> selectAllCommuntiy3();
    @Delete("delete from onlinecommuntiy where id=#{id} and withUserId=0 ")
    int delYiBaiBefroe(@Param("id") Integer id);
    @Insert("insert into addfriend(userId,gmt_create,friendId,isAgree)values(" +
            "#{userId},#{gmt_create},#{friendId},#{isAgree})")
    Integer insertAddFriend(AddFriend addFriend);
    @Select("select *from addfriend where friendId=#{id} order by isAgree=0 ")
    List<AddFriend> selectOneFriend(Integer id);

    @Update("update addfriend set isAgree=#{isAgree} where userId=#{userId} and friendId=#{friendId}")
    int updateFriedn(@Param("userId")Integer id,@Param("friendId") Integer frienId,@Param("isAgree")Integer integer);
    @Delete("delete from addfriend where userId=#{userId} and friendId=#{friendId}")
    Integer delShenqing(@Param("userId")Integer frienId, @Param("friendId") Integer id);

    @Select("select count(1) from addfriend where userId=#{userId} and friendId=#{id}  and isAgree=1")
    Integer selecFindSC(@Param("id") Integer id, @Param("userId") Integer userId);
   /* @Select("select *from addfriend where friend")
    List<AddFriendsUser> selectOneFriedns(Integer id);*/

    @Select("select count(1) from addfriend where userId=#{userId} and friendId=#{friendId}")
    Integer checkIsShenqing(@Param("userId") Integer id, @Param("friendId") Integer friendId);
    @Select("select count(1) from addfriend where userId=#{userId} and friendId=#{friendId} and isAgree=1")
    Integer checkIsAgree(@Param("userId") Integer id, @Param("friendId") Integer userId);
    @Select("select *from addfriend where userId=#{userId} and isAgree=1")
    List<AddFriend> selectOneFried(Integer id);
    @Select("select *from onlinecommuntiy where  (userId=#{userId}  and withUserId=#{withUserId})  or (userId=#{withUserId} and withUserId=#{userId})  order by gmt_create asc")
    List<OnlineCommuntiy> selectOneCommuntiy(@Param("userId") Integer id, @Param("withUserId") Integer id1);
}
